// getNavtopHeight() 获取顶部栏高度
// theme: 顶部栏类型（string），默认'black'表示有返回按钮的顶部条， 'home'表示没有返回按钮的顶部条
// title: 顶部栏标题 (string)
// titleClass: 顶部栏标题的类名 (string), 默认'text-gray-900 font-bold'
// bgColor: 顶部栏背景色 (string), 默认'rgba(247, 252, 255, 0.8)'

Component({
	options: {
		"styleIsolation": "apply-shared"
	},
	properties: {
		theme: {
			type: String,
			value: 'black'
		},
		title: {
			type: String,
			value: ''
		},
		titleClass: {
			type: String,
			value: 'text-gray-900 font-bold'
		},
		bgColor: {
			type: String,
			value: 'rgba(247, 252, 255, 0.8)'
		}
	},
	data: {
		paddingTop: '',
		navBodyHeight: '',
		navHeight: ''
	},
	methods: {
		goBlack(e){
			let pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          prevPage.setData({
               message: e.currentTarget.dataset.msg,
          })
          wx.navigateBack({
               delta: 1,
          })
		},
		getNavtopHeight(){
			const that = this
			// 获取自身高度
			const query = that.createSelectorQuery()
			query.select('#navtop').boundingClientRect()
			query.selectViewport().scrollOffset()
			query.exec(function(res){
				// const navtopHeight = res[0].height + parseInt(that.data.paddingTop.replace('px', '')) + parseInt(16 / 750 * wx.getSystemInfoSync().windowWidth)
				let navtopHeight = res[0].height
  			that.triggerEvent('getNavtopHeight', {navtopHeight})
			})
		}
	},
	ready(){
		// 获取悬浮按钮位置信息
		const menuButton = wx.getMenuButtonBoundingClientRect();
		this.setData({
			paddingTop: menuButton.top + 'px',
			navBodyHeight: (menuButton.height) + 'px',
		})
	},
	pageLifetimes: {
		show: function(){
			const that = this
			setTimeout(()=>{
				that.getNavtopHeight()
			},200)
		}
	}
})